{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import fitz  # PyMuPDF\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "def extract_fonts(pdf_path):\n",
    "    with fitz.open(pdf_path) as doc:\n",
    "        num_pages = doc.page_count\n",
    "        fonts = []\n",
    "        for page_number in range(num_pages):\n",
    "            font_info = doc.get_page_fonts(page_number, True)  # 获取页面字体信息\n",
    "            for font_tuple in font_info:\n",
    "                font_xref = font_tuple[0]\n",
    "                font_ext = font_tuple[1]\n",
    "                font_type = font_tuple[2]\n",
    "                font_name = font_tuple[3]\n",
    "                if font_type != 'Type3':  # 排除Type3字体\n",
    "                    if font_name not in fonts:\n",
    "                        fonts.append(font_name)\n",
    "        return fonts\n",
    "\n",
    "pdf_path = 'sample.pdf'\n",
    "fonts = extract_fonts(pdf_path)\n",
    "print(fonts)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
